package com.fxc.handler;

import com.fxc.MySQLRemoteService;
import com.fxc.crowd.constant.CrowdConstant;
import com.fxc.crowd.util.CrowdUtil;
import com.fxc.crowd.util.ResultEntity;
import com.fxc.entity.VO.PortalTypeVO;
import com.netflix.discovery.converters.Auto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @author FXC
 * @version 1.0
 * @date 2021/12/3 19:48
 */
@Controller
public class PortalHandler {

    @Autowired
    private MySQLRemoteService mySQLRemoteService;

    @RequestMapping("/")
    public String ShowPortalPage(ModelMap modelMap){

        // 1. 调用MySQLRemoteService提供的方法查询首页要显示的数据
        ResultEntity<List<PortalTypeVO>> resultEntity = mySQLRemoteService.getPortalTypeProjectDataRemote();

        // 2.检查查询结果
        String result = resultEntity.getResult();
        if (ResultEntity.SUCCESS.equals(result)){

            // 3.获取数据查询结果
            List<PortalTypeVO> list = resultEntity.getData();

            modelMap.addAttribute(CrowdConstant.ATTR_NAME_PORTAL_DATA, list);
        }

        return "portal";
    }
}
